//
//  GEQLPreviewController.m
//  ERP
//
//  Created by goldeney on 15/4/27.
//  Copyright (c) 2015年 ShangHai Goldeneye Techonology Co.,Ltd. All rights reserved.
//

#import "GEQLPreviewController.h"

@interface GEQLPreviewController ()

@property (nonatomic, strong) NSString *filePath;

@end

@implementation GEQLPreviewController

- (id)initWithPathString:(NSString*)path
{
    self = [super init];
    if (self) {
        self.filePath = path;
        self.title = path ? [[path lastPathComponent]stringByDeletingPathExtension] : @"文件预览";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    QLPreviewController *qlPreviewController = [[QLPreviewController alloc] init];
    qlPreviewController.dataSource = self;
    qlPreviewController.delegate = self.delegate ? self.delegate : self;
    
    if (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0) {
        qlPreviewController.view.frame = CGRectMake(0, 0, SuperWidth, SuperHeight + 44);
        [self addChildViewController:qlPreviewController];
        [self.view addSubview:qlPreviewController.view];
    } else {
        [self addViewController:qlPreviewController];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark QLPreviewControllerDataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}

- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)currentIndex
{
    return [NSURL fileURLWithPath:self.filePath];
}

#pragma mark -
#pragma mark QLPreviewControllerDelegate

- (void)previewControllerWillDismiss:(QLPreviewController *)controller
{
    //隐藏标题栏
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

@end
